<?php

class AccountController extends BackendController
{
    public function actionIndex()
    {
        $this->render('index',array(

        ));
    }

    public function actionLogin()
    {
        $model=Yii::app()->user->model;
        $model->setScenario('login');

        $this->performAjaxValidation($model);

        if(isset($_POST['User']))
        {
            if(Yii::app()->user->loginUser($_POST['User'])){
                Yii::app()->notification->message=Yii::t('account/index','helloUser',array('{user}'=>Yii::app()->user->name));
                $this->redirect(Yii::app()->createUrl('admin/index'));
            }
        }

        $this->render('login',array(

        ));
    }

    protected function performAjaxValidation($model)
    {
        if(isset($_POST['ajax']) && ($_POST['ajax']==='login-form' || $_POST['ajax']==='register-form')){
            echo CActiveForm::validate($model);
            Yii::app()->end();
        }
    }
} 